﻿using Demo.Net.RabbitMQ;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Microsoft.Extensions.DependencyInjection
{
    public static class RabbitMQClientExtensions
    {

        public static IServiceCollection AddRabbitMQClient(this IServiceCollection services,  string name, Action<RabbitMQClientOptions> options)
        {
            name = name ?? throw new ArgumentNullException(nameof(name));
            options = options ?? throw new ArgumentNullException(nameof(options));
            services = services ?? throw new ArgumentNullException(nameof(services));
            //将实例注入到服务容器中，并将获取的选项值赋值给 options 参数。
            services.Configure(name,options);
            services.TryAddSingleton<IRabbitMQFactory, RabbitMQFactory>();
            return services;
        }
    }
}
